// pages/withdrawal/withdrawal.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    user:{},
    phoneNum:'',
    money:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let user = typeof wx.getStorageSync('user')==='string'? JSON.parse(wx.getStorageSync('user')):wx.getStorageSync('user');
    console.log(user);
    this.setData({
      user
    });
  },

  //点击获取验证码触发的函数
  getPhone(e){
    console.log(this.data.phoneNum);
    wx.request({
      url: 'http://192.168.31.101/user/random',
      data: {
        open_id:this.data.user.safetyInfo.open_id,
        user_phone:this.data.phoneNum   
      },
      success: (result) => {
        console.log(result);
      },
    })
  },

  //获取输入手机号绑定的值
  bindKeyInput1(e){
    let phoneNum=e.detail.value;
    this.setData({
      phoneNum
    })
  },

  //获取输入提现金额绑定的值
  bindKeyInput2(e){
    let money=parseFloat(e.detail.value);
    this.setData({
      money
    })
  },

  //输入验证码之后点击确定按钮触发的函数
  goClick(e){
    wx.request({
      url: 'http://192.168.31.101/user/getuser',
      data: {
        open_id:this.data.user.safetyInfo.open_id          
      },
      success: (result) => {
        console.log(result);
        wx.setStorageSync('user', result.data.data);
        this.onLoad();
      },
    })
  },

  //提现完成之后点击确定触发的函数
  submit(){
    wx.request({
      url: 'http://192.168.31.101/safetyInfo/upDaccountMoney',
      data: {
        open_id:this.data.user.safetyInfo.open_id,
        account_money:this.data.money
      },
      success: (result) => {
        console.log(result);
        wx.showToast({
          title: '提现成功',
          duration: 2000,
          icon: 'success'
        })
        this.setData({
          money:''
        })
      },
    })

  }
})